<?php

/**
 * 删除文件
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: DelfileController.class.php v1.0 2014-06-13 17:27:03 $
 */
namespace Admin\Controller;
class DelfileController extends CommonController{

    public function _initialize() {
        parent::_initialize();
    }
    public function index(){
        $verifyToken = md5(C("COOKIE_ENCODE") . I('post.salt'));
        if (I('post.token') == $verifyToken) {
            $filepath = YDCMS_ROOT . I("post.filepath", "");
            if(!preg_match("#[\\|/]Public[\\|/]uploads#", $filepath)){
                return $this->errorReturn("非法操作！");
            }
            
            if(!file_exists($filepath)){
                return $this->errorReturn("您要删除的文件不存在！");
            }
            
            $isDelFile = $this->_delFile($filepath);
            if($isDelFile){
                return $this->successReturn("删除成功");
            }else{
                return $this->errorReturn("删除失败!");
            }
        }else{
            return $this->errorReturn("token验证不通过!");
        }
    }

    private function _delFile($file) {
        if(!file_exists($file)){
            return $this->errorReturn("您要删除的文件不存在！");
        }else{
            return RmRecurse($file);
        }
    }
}
